﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Admin.Core.Common.Input;
using Admin.Core.Common.Output;
using Admin.Core.Common.ParamInput;
using Admin.Core.Service.Xsproject.Project;
using Admin.Core.Service.Xsproject.Project.Input;
using Admin.Core.Service.Xsproject.TaskItem;
using Admin.Core.Service.Xsproject.TaskItem.Input;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Admin.Core.Controllers.Project
{
    public class ProjectController : AreaController
    {
        private readonly IProjectService _projectService;
        private readonly ITaskItemService _taskItemService;

        public ProjectController(IProjectService projectService, ITaskItemService taskItemService)
        {
            _projectService = projectService;
            _taskItemService = taskItemService;
        }

        /// <summary>
        /// 查询单条物料类型信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IResponseOutput> Get(long id)
        {
            return await _projectService.GetAsync(id);
        }


        /// <summary>
        /// 查询分页物料类型信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IResponseOutput> GetPage(PageInput<ConmonFilterInput> model)
        {
            return await _projectService.PageAsync(model);
        }

        /// <summary>
        /// 新增物料类型
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IResponseOutput> Add(ProjectAddInput input)
        {
            return await _projectService.AddAsync(input);
        }





        /// <summary>
        /// 初始化模板
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IResponseOutput> InitModule(CommonIdInput input)
        {
            return await _taskItemService.InitAsync(input);
        }



        /// <summary>
        /// 查询项目的模板
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IResponseOutput> GetTaskList(CommonIdInput input)
        {
            return await _taskItemService.GetAllDetailPageAsync(input.id);
        }



        /// <summary>
        /// 查询项目的甘特图数据
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IResponseOutput> GetGanttData(CommonIdInput input)
        {
            return await _taskItemService.GetGanttDataAsync(input.id);
        }

        /// <summary>
        /// 启动项目
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IResponseOutput> StartProject(CommonIdInput input)
        {
            return await _projectService.StartProjectAsync(input.id);
        }

        /// <summary>
        /// 查询任务下拉
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IResponseOutput> GetTaskItems(CommonPrInput input)
        {
            return await _taskItemService.GetTaskItemsAsync(input.id,input.projectId,input.TaskId);
        }


        /// <summary>
        /// 新增任务
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IResponseOutput> AddTaskItem(TaskItemAddInput input)
        {
            return await _taskItemService.AddAsync(input);
        }

        /// <summary>
        /// 查询任务
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IResponseOutput> GetTaskItem(long id)
        {
            return await _taskItemService.GetTaskItemAsync(id);
        }
        /// <summary>
        /// 修改物料类型
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<IResponseOutput> Update(ProjectUpdateInput input)
        {
            return await _projectService.UpdateAsync(input);
        }


        /// <summary>
        /// 修改任务
        /// </summary>
        /// <param name="uplist"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<IResponseOutput> UpdateTaskItem(List<TaskItemUpdateInput> uplist)
        {
            //return await _taskItemService.UpdateTaskItemAsync(input);
           return  await _taskItemService.UpdateTaskAsync(uplist);
        }

       
        /// <summary>
        /// 删除物料类型
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<IResponseOutput> SoftDelete(long id)
        {
            return await _projectService.SoftDeleteAsync(id);
        }

        /// <summary>
        /// 批量删除物料类型
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<IResponseOutput> BatchSoftDelete(long[] ids)
        {
            return await _projectService.BatchSoftDeleteAsync(ids);
        }

    }
}